# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
import sys
from email.mime.text import MIMEText

import condor_config as config

def notify(plain_msg='JOB DONE!'):
    if config.SENDER == None or config.RECEIVER == None:
        return False

    msg = MIMEText(plain_msg)

    # me == the sender's email address
    # you == the recipient's email address
    msg['Subject'] = 'CPW-Result'
    msg['From'] = config.SENDER
    msg['To'] = ','.join(config.RECEIVER)

    # Send the message via our own SMTP server, but don't include the
    # envelope header.
    s = smtpserver = smtplib.SMTP(config.SMTP_SERVER, config.SMTP_PORT)
    s.ehlo()
    s.starttls()
    s.ehlo()
    s.login(config.SENDER, config.SENDER_PWD)
    s.sendmail(config.SENDER, config.RECEIVER, msg.as_string())
    s.quit()

    return True
